package server

import (
	pb "wire/api/city"

	json "gitee.com/go-mod/framework/response"
	"github.com/gin-gonic/gin"
)

type CityHTTPServer struct {
}

func NewCityHTTPServer() *CityHTTPServer {
	return &CityHTTPServer{}
}

func (s *CityHTTPServer) Get(c *gin.Context) {
	res := &pb.GetReply{
		Info: &pb.CityInfo{
			Id:     102,
			Code:   "sh",
			Name:   "上海",
			Status: 1,
		},
	}
	json.Success(c, res)
}

func (s *CityHTTPServer) All(c *gin.Context) {
	citys := []*pb.CityInfo{
		&pb.CityInfo{
			Id:     101,
			Code:   "bj",
			Name:   "北京",
			Status: 1,
		},
		&pb.CityInfo{
			Id:     102,
			Code:   "sh",
			Name:   "上海",
			Status: 1,
		},
	}

	len := len(citys)
	mapCity := make(map[string]*pb.CityInfo, len)
	hashCity := make(map[string]string, len)
	for _, city := range citys {
		mapCity[city.Code] = city
		hashCity[city.Code] = city.Name
	}

	res := &pb.AllReply{
		List: citys,
		Map:  mapCity,
		Hash: hashCity,
	}
	json.Success(c, res)
}
